package com.atguigu.lease.web.admin.controller.apartment;

import com.atguigu.lease.common.result.Result;
import com.atguigu.lease.common.result.ResultCodeEnum;
import com.atguigu.lease.model.entity.PaymentType;
import com.atguigu.lease.web.admin.service.PaymentTypeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by 小可乐$ on 2024/8/12$ 14:43$
 * description: 支付方式管理
 */
@Tag(name = "支付方式管理")
@RestController
@RequestMapping("/admin/payment")
public class PaymentTypeController {
    @Autowired
    private PaymentTypeService paymentTypeService;

    /**
     * 支付方法更新或添加
     */
    @Operation(summary = "支付方法更新或添加")
    @PostMapping("saveOrUpdate")
    public Result saveOrUpdate(@RequestBody PaymentType paymentType){
        paymentTypeService.saveOrUpdate(paymentType);
        return Result.ok();
    }
    /**
     * 查询全部支付方式列表
     * */
    @Operation(summary = "查询全部列表")
    @GetMapping("list")
    public Result<List<PaymentType>> list(){
        List<PaymentType> paymentType = paymentTypeService.list();
        return Result.build(paymentType, ResultCodeEnum.SUCCESS);
    }
    /**
     * 根据id删除支付方式
     * */
    @Operation(summary = "根据id删除支付方式")
    @DeleteMapping("/deleteById")
    public Result deleteById(@RequestParam Long id){
        paymentTypeService.removeById(id);
        return Result.ok();
    }
}
